package com.cq.hd.app.controller;

import com.cq.hd.app.biz.UserBiz;
import com.cq.hd.app.vo.UserSubscribeStateVo;
import com.cq.hd.common.annotation.LoginUser;
import com.cq.hd.common.entity.AppLoginUser;
import com.cq.hd.common.entity.UserInfo;
import com.cq.hd.common.response.Result;
import com.cq.hd.common.response.ResultGenerator;
import com.cq.hd.member.api.dto.AppUserPwdUpdateDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@RequestMapping("/user")
@Api(tags = "用户相关接口")
public class AppUserController {

    @Autowired
    private UserBiz userBiz;

    @ApiOperation(value = "获取用户/商家详细信息")
    @ApiResponse(response = UserInfo.class, code = 200, message = "接口返回对象参数")
    @GetMapping("/getUserInfo")
    public Result<UserInfo> getUserInfo(@ApiIgnore @LoginUser AppLoginUser appLoginUser) {
        return ResultGenerator.success(userBiz.getUserInfo(appLoginUser));
    }

    @ApiOperation(value = "获取用户关注微信公众号状态")
    @ApiResponse(response = UserSubscribeStateVo.class, code = 200, message = "接口返回对象参数")
    @GetMapping("/getSubscribeState")
    public Result<UserSubscribeStateVo> getSubscribeState(@ApiIgnore @LoginUser AppLoginUser appLoginUser) {
        return ResultGenerator.success(userBiz.getSubscribeState(appLoginUser));
    }

    @ApiOperation(value = "修改登录密码")
    @PutMapping("/updatePwd")
    public Result<Boolean> updatePwd(@ApiIgnore @LoginUser AppLoginUser appLoginUser,
                                     @RequestBody AppUserPwdUpdateDto appUserPwdUpdateDto) {
        appUserPwdUpdateDto.setId(appLoginUser.getUserId());
        return userBiz.updatePwd(appUserPwdUpdateDto);
    }
}
